package com.yellowpage.bigdata.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.yellowpage.bigdata.data.NspFatallogImeiDayregionSum;
import com.yellowpage.bigdata.service.NspFatallogImeiDayregionSumService;
import com.yellowpage.ca.data.User;
import com.yellowpage.ca.service.RegionService;
import com.yellowpage.white.struts.BaseAction;

public class NspFatallogImeiDayregionCountAction extends BaseAction{
	
	private NspFatallogImeiDayregionSum nspFatallogImeiDayregionSum;
	private NspFatallogImeiDayregionSumService nspFatallogImeiDayregionSumService;
	
	private String selectedId;
	private String query_logDate;
	private String query_requestType;
	private String query_logDate_end;
	private Map<String, String> regionMap;
	public Map<String, String> getRegionMap() {
		return regionMap;
	}
	public void setRegionMap(Map<String, String> regionMap) {
		this.regionMap = regionMap;
	}
	public String getRegionName() {
		return regionName;
	}

	public void setRegionName(String regionName) {
		this.regionName = regionName;
	}

	private String regionName;
	private List<Map> resultList = new ArrayList<Map>();
	private Map requestTypeMap = new HashMap();
	private RegionService regionService;
	public RegionService getRegionService() {
		return regionService;
	}

	public void setRegionService(RegionService regionService) {
		this.regionService = regionService;
	}
    public String getRegionSql(){
    	  Map session = ActionContext.getContext().getSession();
    	  User user = (User) session.get("userObject");
    	  String function_code= "OMC_ABILITYCALL_LOG_COUNT_DAY_REGIONCOUNT";
    	  String regionsql= regionService.getRegionclauseByUserFunction(user.getUserId(), function_code, "REGION_CODE");
    	 return regionsql;
    }

	public void prepare() {
		super.prepare();
		// 加载请求类型
		requestTypeMap = nspFatallogImeiDayregionSumService.getrequestTypeMap();
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.nspFatallogImeiDayregionSum = nspFatallogImeiDayregionSumService
					.getNspFatallogImeiDayregionSum(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {
		initPageRender();

		Map queryMap = new HashMap();
		Map queryMap_1 = new HashMap();
		queryMap.put("requestType", query_requestType);
		if(!regionName.equals("")){
			regionMap = nspFatallogImeiDayregionSumService.getRegionMap(getRegionSql());
			String[] val = regionName.split(";");
			String str = "(";
			for(String ss : val){
				for(String key : regionMap.keySet()){
					if(regionMap.get(key).contains(ss)){
						str += "'" + key + "',";
						break;
					}
				}
			}
			str= str.substring(0, str.length() - 1)+")";
			queryMap.put("regionCode", str);
		}else{
			queryMap.put("regionCode", regionName);
		}
		queryMap.put("logDate", query_logDate);
		queryMap.put("query_logDate_end", query_logDate_end);

		resultList = nspFatallogImeiDayregionSumService
				.queryNspFatallogDayregionCountByPage(queryMap, pageRender);

		setPageRenderToRequest();

		return "query";
	}

	public String queryChannel(){
		initPageRender();
		regionMap = nspFatallogImeiDayregionSumService.getRegionMap(getRegionSql());
		setPageRenderToRequest();
		return "toRegion";
	}
	public NspFatallogImeiDayregionSum getNspFatallogImeiDayregionSum() {
		return nspFatallogImeiDayregionSum;
	}

	public void setNspFatallogImeiDayregionSum(
			NspFatallogImeiDayregionSum nspFatallogImeiDayregionSum) {
		this.nspFatallogImeiDayregionSum = nspFatallogImeiDayregionSum;
	}

	public NspFatallogImeiDayregionSumService getNspFatallogImeiDayregionSumService() {
		return nspFatallogImeiDayregionSumService;
	}

	public void setNspFatallogImeiDayregionSumService(
			NspFatallogImeiDayregionSumService nspFatallogImeiDayregionSumService) {
		this.nspFatallogImeiDayregionSumService = nspFatallogImeiDayregionSumService;
	}

	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String getQuery_logDate() {
		return query_logDate;
	}

	public void setQuery_logDate(String query_logDate) {
		this.query_logDate = query_logDate;
	}

	public String getQuery_requestType() {
		return query_requestType;
	}

	public void setQuery_requestType(String query_requestType) {
		this.query_requestType = query_requestType;
	}

	public String getQuery_logDate_end() {
		return query_logDate_end;
	}

	public void setQuery_logDate_end(String query_logDate_end) {
		this.query_logDate_end = query_logDate_end;
	}


	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}

	public Map getRequestTypeMap() {
		return requestTypeMap;
	}

	public void setRequestTypeMap(Map requestTypeMap) {
		this.requestTypeMap = requestTypeMap;
	}
}
